local common = require("apigateway.common")
local urlwhitelist = require("apigateway.url_whitelist")
local ip = common.redis_config["ip"]
local port = common.redis_config["port"]
--检查token是否存在
local function check_token()
	local token = ngx.req.get_headers()["token"]
	if not token then
		if urlwhitelist.check_url_whitelist() then
			-- TODO
		else
			ngx.exit(ngx.HTTP_UNAUTHORIZED)
		end
	else
		local t = common.read_redis(ip,port,{token})
		if not t  then
			ngx.exit(ngx.HTTP_UNAUTHORIZED)
		end
	end
end

local _M = {
	check_token = check_token
}
return _M
